package com.newtouch.conf.demo.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;

@Service
public class NboConfDemoTask {
    // 日志输出
    protected static final Logger LOGGER = LoggerFactory.getLogger(NboConfDemoTask.class) ;
    public int run (){
        try {
            while (true){
                Thread.sleep(5000);
                LOGGER.info("==============redis system.out 输出 start=======================");
                String path = this.getClass().getResource("/").getPath() ;
                System.out.println(path);// 获得类加载路径
                File file = new File(path);// 根据类加载路径查看类文件
                if (!file.exists()) {// 判断此路径下是否有文件或文件夹
                    System.out.println(path + " 没有文件");
                }
                File[] files = file.listFiles() ;
                for (File file1 : files) {
                    String fileName = file1.getName() ;
                    if (fileName.equalsIgnoreCase("redis.properties")) {
                        Properties properties = new Properties() ;
                        FileInputStream fileInputStream = new FileInputStream(path+fileName) ;
                        properties.load(fileInputStream);
                        LOGGER.info("redis( {} , {} )",properties.getProperty("redis.host"), properties.getProperty("redis.port"));
                    }
                }
                LOGGER.info("==============redis system.out 输出 end=======================");
            }
        }catch (Exception e){
            LOGGER.error(e.toString(),e);
        }
        return 0;
    }


}
